package metu.tespit.entity.course;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;



import metu.tespit.entitiy.accountManagement.User;
import metu.tespit.entity.semester.Semester;

/**
 
 * @created 13 Nis 2012
 */

@Entity
@Table(name="course")
public class Course implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7242723934825177959L;

	@Id @GeneratedValue
	private Long id;

	@Column(unique = true)
	private String code;
	
	private String Name;
	
	@ManyToOne
	private User instructor;
	
	@ManyToOne
	private User teachingAssistant;
	
	@ManyToMany
	private List<User> students=new ArrayList<User>();
	
	@ManyToOne
	private Semester semester;
	
	@OneToOne(cascade=CascadeType.ALL, mappedBy="course")
	private Schedule schedule;
	
	@OneToMany(cascade=CascadeType.ALL, mappedBy="course")
	private List<Announcement> announcements=new ArrayList<Announcement>();
	
	@OneToMany(cascade=CascadeType.ALL, mappedBy="course")
	private List<LectureNote> lectureNotes=new ArrayList<LectureNote>();
	
	@OneToMany(cascade=CascadeType.ALL, mappedBy="course") 
	private List<ProjectTeam> projectTeams=new ArrayList<ProjectTeam>();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public Semester getSemester() {
		return semester;
	}

	public void setSemester(Semester semester) {
		this.semester = semester;
	}

	public Schedule getSchedule() {
		return schedule;
	}

	public void setSchedule(Schedule schedule) {
		this.schedule = schedule;
	}

	public List<Announcement> getAnnouncements() {
		return announcements;
	}

	public void setAnnouncements(List<Announcement> announcements) {
		this.announcements = announcements;
	}

	public List<LectureNote> getLectureNotes() {
		return lectureNotes;
	}

	public void setLectureNotes(List<LectureNote> lectureNotes) {
		this.lectureNotes = lectureNotes;
	}

	public List<ProjectTeam> getProjectTeams() {
		return projectTeams;
	}

	public void setProjectTeams(List<ProjectTeam> projectTeams) {
		this.projectTeams = projectTeams;
	}

	public void setInstructor(User instructor) {
		this.instructor = instructor;
	}

	public User getInstructor() {
		return instructor;
	}

	public void setTeachingAssistant(User teachingAssistant) {
		this.teachingAssistant = teachingAssistant;
	}

	public User getTeachingAssistant() {
		return teachingAssistant;
	}
	
	public List<User> getStudents() {
		return students;
	}

	public void setStudents(List<User> students) {
		this.students = students;
	}
	public List<Announcement> getAnnouncementsLimited(){
		
		if(this.announcements.size()<=5){
			return this.announcements;
		}
		else{
			return this.announcements.subList((this.announcements.size()-5), (this.announcements.size()));
			
		}
		
	}
	
}
